package com.qf.mvc2203.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

@Controller  // 代表当前类是一个 springmvc 框架中的后端控制器类
@RequestMapping("/user")  // 匹配路径
public class DengluController  {
    /**
     *
     * @return 返回值代表视图的名称。注意，只有当Controller类上面加@Controller 注解时，String类型的返回值
     * 才代表视图名称。
     */
    @RequestMapping("/login")
    public void test1(HttpServletRequest request, HttpServletResponse response) throws IOException, IOException {
        //0.设置编码格式
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        //1.
        String value = request.getParameter("value");
        //2.
        String  result = null;
        if (value.equals("root") | value.equals("admin")) {
            result = "2";
            //代表已经存在
        }else{
            //可以注册
            result = "1";
        }
        //3.
        response.getWriter().write(result);
    }
}
